/*******************************************************************************
 * @doc UCL
 * @module UCLCOMM.C |
 * Source code for the UCL communication functions.
 *
 * Product         :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   SoftPay Development Team (I_SP2000).
 * <nl>Notes       :
 *
 * @head3 UCL Functions |
 * @index | UCL
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * Date						Author								Purpose			
 * 09-Sep-2005			CHIA Lee Chyi				Implementation of display for battery charging
 * 09-Dec-2005			TEO Kia Soon				Implementation of LAN and WIFI on UCL library
 * ------------------------------------------------------------------------
$Log: /SoftPay/SPK2SIM/Source/UCL/uclcomm.c $
 * ------------------------------------------------------------------------
 ********************************************************************************/
#include <project.h>

#include <ascii.h>
#include <txoinc.h>
#include <acldev.h>
#include <stdio.h>
#include <svc.h>
#include <aclutil.h>
#include <device.h>
#include <aclconio.h>
#include <string.h>
#include <stdlib.h>

//#define DEBUG_VSMODEM
//#ifdef DEBUG_VSMODEM
#define DEBUG_95
//#endif

#include <define.h>
#include <transact.h>
#include <sizes.h>
#include <funcids.h>
#include <init.h>
#include <oper.h>
#include <msg.h>
#include <msgfuncs.h>
#include <comm.h>
#include <gds.h>
#include <tran.h>
#include <ui.h>
#include <logsys.h>
#include <spdebug.h>
#include <operate.h>
#include <confio.h>
#include <date.h>
#include <mem.h>
#include <menufunc.h>
#include <table.h>      /* For inGetFunctionPointer() prototype */
#include <pcounter.h>
#include <tct.h>
#include <ipt.h>
#include <confproto.h>
//#include <sqautils.h>
#include <logo.h>
#include <form.h>
#include <format.h> //ANNAVIDS

#include <power.h> 	//LeeChyi - 09092005: Added
#include <Menus.h>	//KiaSoon - 12122005: Added

#include "uclfactory.h"       // Header file for UCL Factory class
#include "verixtimer.h"      // Header file for Lib defined VerixCommTimer class
#include "tcpinterface.h"		// Header file for UCL Factory class
//#include "netsetup.h"
#include "vsocket.h"
#include "inet.h"
#include "vtcpip.h"
#include "AppObj.h"
#include "UCLComm.h"
#include "UCLids.h"

#include "ucldefine.h"
#include "hostdata.h"

extern VS_BOOL fTCUploadCloseModem; //LeeChyi - Added in for EMV

extern char* szGetHostPrimaryIP(void);

#include "..\cpacsrc\sqautils.h"
//#include "..\cpacsrc\cpacextn.h"
// Added by Anna Vida Garcia - Added include files as needed bythe modifications made with the printing of error msgs
//#include "..\netssrc\NETSmsg.h"
//#include "..\netssrc\NETSsize.h"
//#include "..\netssrc\NETSids.h"
// End of modifications - AVG

// Added by Anna Vida Garcia - Added the declarations needed for the printing of error msgs as per NETS requirements
#define REPRINT_FILE_NAME_NETS		"NETSREPRINT.RCT"
extern int inRunFunction(TRANSACTION_OBJECT* pobTran,int inFieldID); // added by Andy_F1

// Added by Andy_F1
extern int inWriteBatchData(DB_FILE* psrDBF,BATCH_KEY* psrBKey,BATCH_REC* psrBRec,long lnRecNum);
extern int inCloseBatch(DB_FILE* psrDBFPtr);


#if 0
extern void vdNETSGetReceiptHeader(TRANSACTION_OBJECT* pobTran);
extern void vdNETSGetReceiptTop(TRANSACTION_OBJECT* pobTran);
extern void vdNETSGetReceiptMiddle(TRANSACTION_OBJECT* pobTran);
extern void vdNETSGetReceiptBottom(TRANSACTION_OBJECT* pobTran);
extern void vdNETSSetReceiptHeaderCondition (TRANSACTION_OBJECT *pobTran);
extern void vdNETSSetReceiptTopCondition (TRANSACTION_OBJECT *pobTran);
extern void vdNETSSetReceiptMiddleCondition (TRANSACTION_OBJECT *pobTran);
extern void vdNETSSetReceiptBottomCondition (TRANSACTION_OBJECT *pobTran);
extern int inGetReceiptTemplate(TRANSACTION_OBJECT *pobTran);
extern int  inNETSMultipleDownloadLogo (int inWhichOne); //ANNAVIDS
#endif

VS_BOOL fError;
// End of modifications - AVG
extern long lnDialErrorNo; //albert_d1

//  Creating object for UclFactory structure
UclFactory *uclFactory;

//  Ucl Pointer to hold the communication Object
Ucl* comnObj;

AppObj *gsmAppObj;
AppObj *gprsAppObj;
AppObj *COAppObj;
//  Creating object for VerixCommTimer structure
CommTimer *timer;
int hEthernet=0;
int hSocket;
VS_BOOL fOpenSocket;
VS_BOOL fEndTCP;
//VS_BOOL fInitComm;
int fInitComm;
extern int hLan;
//albert_d1 for pre_connection
VS_BOOL pre_connection=VS_FALSE;
VS_BOOL fSocketRetry=VS_FALSE;

extern COMM_OBJECT obCommunication;

char szHostIP[30+1];
char* szPort = NULL;
//short  retVal = 0;
int GPRShandle;
int inSignalStrength;					// Frederick_L1, global variable for signal strength
int inGPRSNetStatus;					// Frederick_L1, global variable for GPRS netowrk status
int inWIFINetStatus;					// KiaSoon, Global variable for WIFI network status
int inBatteryStatus;					// Albert_D1, global variable for battery status
unsigned long ulCheckTimeout=0L;		// Frederick_L1, for checking out the GPRS status
char SendBuff[1024 + 1];
char ReceiveBuff[1024 + 1];

/* LeeChyi - 16092005: START */
unsigned long ulTimer;
int inPDPContextStatus;
int inGPRSStatus;	
char szPingIP[16];
VS_BOOL fRetryGPRS;
/* LeeChyi - END */

void vdAddUCLFunctions( void )
{
	inAddFunctionPointer(UCL_INIT, (PFI)inUCLInitialize);
	//inAddFunctionPointer(UCL_INIT_WIFI, (PFI)inUCLWiFiInitialize);
	//inAddFunctionPointer(PRE_CONNECTION, inPreConnection);
	inAddFunctionPointer(UCL_INIT_GPRS,(PFI) inUCLGPRSInitialize);
	inAddFunctionPointer(EDIT_GPRS,inEditGPRSOperation); //gprs
	inAddFunctionPointer(EDIT_MGT,inEditMGTOperation);//gprs
	inAddFunctionPointer(CHECK_GPRS_STATUS, inCheckGPRSStatus);
	inAddFunctionPointer(CHECK_WIFI_STATUS, inCheckWIFIStatus);
	inAddFunctionPointer(CHECK_RADIO_STATUS, inCheckUCLStatus); // KiaSoon: common function for radio 

	inAddFunctionPointer(CHECK_FORCE_REBOOT, inCheckForceReboot);
	inAddFunctionPointer(RESET_FORCE_REBOOT, inResetForcereboot);
}


/*********************************************************************************************
* @func void | vdInitializeUCLComm |
*		Sets the function pointers and the link type in the communication
*		object.
*
* @parm COMM_OBJECT *| obCommunication |
*		Communication object
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/
void vdInitializeUCLComm(COMM_OBJECT *obCommunication)
{
	int inRadio=get_env_int("*RADIO");
	
	if(inRadio == GPRS_RADIO)
	 {
	 	obCommunication->inLinkType	= UCL_GPRS_COMM;
		obCommunication->fLinkUp = VS_FALSE;
		obCommunication->inInitialize	= (PFI_VD)inInitUCLGPRSCommunication;
		obCommunication->inBegin		= (PFI_PFOR_BEGIN)inBeginUCLGPRSCommunication;
		obCommunication->inCheck		= (PFI_VD)inCheckUCLGPRSCommunication;
		obCommunication->inSend 		= (PFI_PFOR_SEND)inSendUCLGPRSCommunication;
		obCommunication->inReceive		= (PFI_PFOR_RES)inReceiveUCLGPRSCommunication;
		obCommunication->inEnd			= (PFI_VD)inEndUCLGPRSCommunication;
		obCommunication->inFlush		= (PFI_VOID)inFlushUCLGPRSCommunication;
		obCommunication->inDeinitialize = (PFI_VD)inDeInitUCLGPRSCommunication;
	}
       else
       {
       		pre_connection=VS_FALSE;
		obCommunication->inInitialize		= (PFI_VD)inInitUCLETHCommunication;
		obCommunication->inBegin			= (PFI_PFOR_BEGIN)inBeginUCLETHCommunication;
		obCommunication->inCheck			= (PFI_VD)inCheckUCLETHCommunication;
		obCommunication->inSend 			= (PFI_PFOR_SEND)inSendUCLETHCommunication;
		obCommunication->inReceive		= (PFI_PFOR_RES)inReceiveUCLETHCommunication;
		obCommunication->inEnd				= (PFI_VD)inEndUCLETHCommunication;
		obCommunication->inFlush			= (PFI_VOID)inFlushUCLETHCommunication;
		obCommunication->inDeinitialize  = (PFI_VD)inDeInitUCLETHCommunication;
	}
}

int inUCLInitialize(void)
{
	int inRadio=get_env_int("*RADIO");
	int inTotal=inGetHDTTotRecs();
	int inIndex;
	short shLinktype;
	int inRetVal;
	
	if(inRadio == GPRS_RADIO || inRadio ==ETHERNET_RADIO)
		shLinktype=7; //gprs
	else	
		shLinktype=1; //dial up
		
	for(inIndex=0; inIndex < inTotal; inIndex++)
	{
		if(inLoadHDTRec(inIndex) != VS_SUCCESS)
			return VS_ERR;

		vdSetCommLinkType(shLinktype);
		vdSetSettleCommLinkType(shLinktype);

		if(inSaveHDTRec(inIndex) != VS_SUCCESS)
			return VS_ERR;
	}
	
	if(inRadio == GPRS_RADIO)
		inRetVal=inUCLGPRSInitialize();
	else if (inRadio == ETHERNET_RADIO){
		inRetVal=inUCLETHInitialize();
	}
	return VS_SUCCESS;
	
	
}

int inUCLGPRSInitialize(void)
{
	short  retVal = 0;
	short time=0;
	unsigned long complTime = 0;
	unsigned long startTime = 0;
	//char buffer[5];
	char szTIP[20]; //Added by Anna Vida Garcia
	char azApn[20+1];
	int inIndex;
	short shLinktype;
	int inTotal=inGetHDTTotRecs();
	int inRadio=get_env_int("*RADIO"),inProfile=get_env_int("*PROFILE");

	if(inLoadGPTRec((inProfile-1)) != VS_SUCCESS)
	{
		return VS_ERR;
	}

	memset(azApn, 0x00, sizeof(azApn));
	strcpy(azApn, szGetAPN());

	memset(szTIP, 0x00, sizeof(szTIP));
	strcpy(szTIP, szGetTerminalIP());
	
	if(strlen(azApn) == 0 || strlen(szTIP) == 0)
		return VS_SUCCESS;

	//  Creating object for UclFactory structure
	uclFactory = CreateUclFactory();

	//  Creating object for VerixCommTimer structure
	timer = (CommTimer*)CreateVerixCommTimer();

	gprsAppObj = CreateAppObj(2); // for GPRS
	
	#if __thumb //start albert_d1 07202005 - One-Source
	comnObj = uclFactory->Create(COM2, &retVal, (ApplicationObj *)gprsAppObj,GPRS);
	#else
	comnObj = uclFactory->Create(COM3, &retVal, (ApplicationObj *)gprsAppObj,GPRS);
	#endif //end albert_d1 07202005 - One-Source
	
	timer->SetTimer(2000L);
	retVal = AssignUcltoTCP(comnObj,timer,20000L,60000L,30000L,15000L,6000L,6000L);
	LOG_PRINTF(("AssignUcltoTCP retVal = %d,", retVal));
	
	SocketProgram(1,VS_FALSE);
	
	return VS_SUCCESS;

}

int SocketProgram(int BlockMode,VS_BOOL reconnect)
{
	short  retVal = 0;
	short errNo = -1;
	netparams net_param;

	char* szUsername;
	char* szPassword;
	char* szSubnet;
	char szBuff[100];
	char* szPhoneNo;
	char* szAPN;
	
	/* LeeChyi - 15092005: Added*/
	unsigned int inOnOffValue;
	
	int inProfile=get_env_int("*PROFILE");
	
	retVal = -1;

	szUsername = NULL;
	szPassword = NULL;
	szSubnet = NULL;
	szPhoneNo = NULL;
	szAPN = NULL;
	
	memset(szBuff, 0x00, sizeof(szBuff));
	
	//LeeChyi - 16092005: Modified
	//if(inLoadGPTRec(0) != VS_SUCCESS)
	 if(inLoadGPTRec(inProfile-1) != VS_SUCCESS)
	 	return VS_ERR;

	 szUsername = szGetUsername();
	 LOG_PRINTFF((0x8L,"szUsername=%s",szUsername));

	 szPassword = szGetPassword();
	 LOG_PRINTFF((0x8L,"szPassword=%s",szPassword));

	 szSubnet = szGetSubNetMask1();
	 LOG_PRINTFF((0x8L,"szSubnet=%s",szSubnet));

	 szAPN = szGetAPN();
	 LOG_PRINTFF((0x8L,"szAPN=%s",szAPN));

	 szPhoneNo = szGetPhoneNoGprs();
	 LOG_PRINTFF((0x8L,"szPhoneNo=%s",szPhoneNo));

	// Modified by Frederick Lachica
	// This is to support the static IP address for the GPRS UCL object which is previously only supports dynamic IP address
	// This changes will also support dynamic ip address as long as the user input "0.0.0.0" on the field Terminal IP
	strcpy(net_param.ipAddress ,szGetTerminalIP());
	strcpy(net_param.ipSubnetMask ,szSubnet);
	net_param.datalinkProtocol = DL_PPP_APP_DEFINED;
	strcpy(net_param.linkparams.appparams.ispPassword, szPassword);
	strcpy(net_param.linkparams.appparams.ispUserid, szUsername);

	retVal = SetTimeout(SEND_TIMEOUT,50L);
	retVal = SetTimeout(RECEIVE_TIMEOUT,80L);
	
	vdSetEntryFont(VS_TRUE);
	
	if(reconnect != VS_TRUE){
		retVal = netconfig(&net_param);
	}
	else{
		/* LeeChyi - 07102005: Added in for display purposes */
		if (fSocketRetry == VS_FALSE){
			gotoxy(2, 4);
			vdDisplayFontChar(UTILITY_FONT, 42);
		}
		
		retVal = getnetconfig(&net_param);
	}

	 
	
	 if(retVal >=0)
	 {
	
		netdisconnect(BlockMode);
		
		// END Frederick_L1
		if(reconnect == VS_TRUE){
			/* LeeChyi - 16092005: Commented off following sentence for display purposes */
			/* vdDisplayAt(3,8, (char *)"RECONNECTING GPRS...", CLR_LINE); */
		}
		else
			vdDisplayAt(1,8, (char *)"CONNECTING GPRS...", CLR_LINE);
	 			
		
		retVal = netconnect(BlockMode);
		
		if (retVal >= 0){
			LOG_PRINTF(("netconnect SUCCESS"));
		}
		else{
			LOG_PRINTF(("netconnect FAILED"));
		}
		
		/* LeeChyi - 15092005: START
			When there is a NETCONNECT failure, prompt for the user to RETRY.
			If YES - Application will keep on retrying
			If NO - Application will not retry.
		*/
		if(retVal >=0 && reconnect != VS_TRUE)
		{	
			fRetryGPRS = VS_TRUE; //Any subsequent failures in connection, a reconnection will be triggered automatically
			vdDisplayAt(1,8, (char *)"NETCONNECT SUCCESS", CLR_LINE);
			SVC_WAIT(100);
			vdDisplayAt(1,8, (char *)" ", CLR_LINE);
		}
       else
		{
			if(reconnect == VS_FALSE)
			{
				/* LeeChyi - 15092005: START
					For display purposes.
				*/
				vdDisplayAt(1,1, (char *)" ", CLR_LINE);
				vdClear_8X21_Window(1, 8, 21, 8);
   
   				inOnOffValue = obDisp.inDO_ChooseOne("NETCONNECT FAILED", "RETRY?", "YES~NO", 2, NULL_PFI);
   		
   				/* inOnOffValue = 1: YES; inOnOffValue = 2: NO */
   		
   				if (inOnOffValue == 1){
   					fRetryGPRS = VS_TRUE;
   				}
   				else {
   					fRetryGPRS = VS_FALSE;
   				}			
			
	   			//Original Code - Commented off - vdDisplayAt(1,8,(char *)"NETCONNECT FAILED", CLR_EOL);
			}
       }
       /* LeeChyi - END */

	}
	
	if (fSocketRetry == VS_FALSE)
		vdSetIdleFont(VS_TRUE);
	
	return(VS_SUCCESS);
}
/*********************************************************************************************
* @func int | inInitUCLGPRSCommunication |
*		Allocates memory to the data pointer in the communication object
*
* @parm COMM_OBJECT *| obCommunication |
*		Communication object
*
* @rdesc return values.
* @flag int |  VS_ERR or VS_SUCCESS
* @end
**********************************************************************************************/

int inInitUCLGPRSCommunication (COMM_OBJECT *obCommunication)
{

     //commtype = 1;
	 return(VS_SUCCESS);

}

int inBeginUCLGPRSCommunication(COMM_OBJECT *obCommunication, int inCPTIndex, VS_BOOL fUsePrimaryLine)
{
	
	int inNumTry = 0;
	
	/*LeeChyi - 16092005 - Commented off */
	//int inGPRSStatus;
	int inRetVal;
	char cmd[10];
	unsigned char respBuffer[MAX_RESPONSE_LEN];
	
	//char temp[20+1];
	// Added by Anna Vida Garcia - Added the declarations needed for the printing of error msgs as per NETS requirements
	TRANSACTION_OBJECT* pobTran;
	pobTran = pstGet_pobTran ();
	// End of modifications - AVG
	
	LOG_PRINTF(("*** inBeginUCLGPRSCommunication ***"));
	
	if (inGPRSStatus == DISCONNECTED)
	{
		/* LeeChyi - 16092005: Start */
		/* Consider disabling this check - let the function inCheckGPRSStatus do the reconnecction */
		/*
		vdClearNonTitleLines();
		vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine - 1, (char *)"Reconnecting GPRS...", CLR_EOL);
		vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, (char *)"PLEASE WAIT", CLR_EOL);
		netdisconnect(1);
		vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine - 1, (char *)" ", CLR_EOL);
		vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, (char *)"CONNECTING TO GPRS...", CLR_EOL);
		
		inRetVal = netconnect(1);
		
		if (inRetVal >= 0)
		{
			//LOG_PRINTFF((0x8L,"NETCONNECT SUCCESS"));
			ACTIVITY_LOG("NETCONNECT SUCCESS");
			vdDisplayAt(1,7, (char *)"NETCONNECT SUCCESS", CLR_EOL);
		}
       	else
		{
			//LOG_PRINTFF((0x8L,"NETCONNECT FAILED"));
			//ACTIVITY_LOG("NETCONNECT FAILED");
			vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine - 1, (char *)" ", CLR_EOL);
			vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, (char *)"NETCONNECT FAILED", CLR_EOL);
	       get_char();
			return VS_ERR;
		}
		*/
		
		/* Just return error */
		return VS_ERR;
		
		/* LeeChyi - END */
		
	}
	
	/* LeeChyi - 16092005: START */
	/* Add a check to determine signal strength and PDP Context status:
		If signal strength is less than minimum required to transmit/receive data or
		currently not in PDP Context, return error; since there is no way to establish
		a socket with the host
	*/
	if (inSignalStrength < MIN_SIGNAL	|| inPDPContextStatus != UCL_SUCCESS){
		LOG_PRINTF(("inBeginUCLGPRSCommunication: inSignalStrength=%d", inSignalStrength));
		LOG_PRINTF(("inBeginUCLGPRSCommunication: inPDPContextStatus=%d", inPDPContextStatus));
		return VS_ERR;
	}
	
	inLoadMGTRec((int)shGetHostGroupRef());//load host ip and port

	GPRShandle=-1;
	
	/* LeeChyi - 07102005: 
		Change inNumTry from 2 to 3. 
		1st attempt is to connect to Primary Host.
		2nd attempt is to connect to Secondary Host
		3rd attempt is to do a netdisconnect and connect
		4th attempt is to connect back to Primary Host */
		
	/* while (inNumTry < 2) */
	while (inNumTry < 5)
	/* LeeChyi - END */
	{			
		if(GPRShandle >= 0)
		{
			break;
		}
		else
		{
					
			if(inNumTry == 0) //use primary host ip and port
			{
				inNumTry++;
				GPRShandle=Socket_Connect((unsigned char *) szGetPriPort(), (unsigned char *) szGetPriIP());
				continue;
			}
			else if(inNumTry == 1)//use secondary host ip and port
			{
				inNumTry++;
				GPRShandle=Socket_Connect((unsigned char *) szGetSecPort(), (unsigned char *) szGetSecIP());
				continue;
			}
			/* LeeChyi - 07102005: START */
			else if (inNumTry == 2)
			{
				
				inNumTry++;
				
				/* inSignalStrength = comnObj->GetStatus(comnObj, ABS_SIGNAL, timer);	
				LOG_PRINTF(("inBeginUCLGPRSCommunication: inSignalStrength=%d", inSignalStrength));
				
				memset(cmd, 0, 10);
		 		memset(respBuffer, 0, MAX_RESPONSE_LEN);
				LOG_PRINTF(("Send Command to deactivate PDPContext"));
				strcpy(cmd,"AT+CGACT=0,1");
				comnObj ->SendCommand(comnObj, (unsigned char *)cmd, strlen(cmd),respBuffer, timer);
				LOG_PRINTF(("Response: %s", respBuffer));
				
				memset(cmd, 0, 10);
		 		memset(respBuffer, 0, MAX_RESPONSE_LEN);
				LOG_PRINTF(("Send Command to detach"));
				strcpy(cmd,"AT+CGATT=0");
				comnObj ->SendCommand(comnObj, (unsigned char *)cmd, strlen(cmd),respBuffer, timer);
				LOG_PRINTF(("Response: %s", respBuffer)); */
				
				fSocketRetry = VS_TRUE;
				SocketProgram(1,VS_TRUE);
				fSocketRetry = VS_FALSE;
				
				continue;
			}
			else if (inNumTry == 3)
			{
				inNumTry++;
				GPRShandle=Socket_Connect((unsigned char *) szGetPriPort(), (unsigned char *) szGetPriIP());
				continue;
			}
			/* LeeChyi - END */
			
		 	return VS_ERR;
		}
	}
	return VS_SUCCESS;
}

int inCheckUCLGPRSCommunication(COMM_OBJECT *obCommunication)
{
	
	return VS_SUCCESS;
}

int inSendUCLGPRSCommunication(COMM_OBJECT *obCommunication, char *pchSendBuff, int inSendSize,
								VS_BOOL fConfirmSend, int inTimeout, long lnMessage)
{
	short  shRetVal = 0;
	char szTransmitBuffer[1024+1];
	char szTmp[25];
	char szHex[25];

	memset(szTransmitBuffer, 0x00, sizeof(szTransmitBuffer));
	memset (szTmp, 0x00 , sizeof(szTmp));

	if (lnMessage != 0L)
		vdDisplayMessageFromFile( lnMessage, STATUS_MSG);

	// START Frederick_L1 071304, check the GPT table which format of length header to be send to host
	if (fGetHexHeader())	// if true then HEX format header else BCD format header
		sprintf(szTmp, "%04X", inSendSize);	// changes due to hypercom NAC, July 1, 2004
	else
		sprintf(szTmp, "%04d", inSendSize);

    SVC_DSP_2_HEX(szTmp, szHex, 2);

	memcpy (szTransmitBuffer, szHex, 2);
	memcpy(&szTransmitBuffer[2],pchSendBuff,inSendSize);
	shRetVal = send(GPRShandle, szTransmitBuffer, inSendSize+2,0);
	shRetVal = inSendSize;

	memset(SendBuff, '\0', sizeof(SendBuff));
	memcpy(SendBuff, pchSendBuff, inSendSize+2);
	if (shRetVal == VS_ERR)// Frederick_L1, If failed to send data, set the transaction error to SEND FAILED to inform user
		if (errno == ETIMEDOUT)
			shRetVal = VS_TIMEOUT;
	
	return shRetVal;
}

int inReceiveUCLGPRSCommunication(COMM_OBJECT *obCommunication, char *pchReceiveBuff, int inReceiveSize,
								 int inReceiveTimeout, long lnMessage)
{
	short  retVal = 0;
	struct timeval  mytimeval;
	int inGPRSRespValidation=0;
	//char buff[10];

	memset(ReceiveBuff, 0x00, sizeof(ReceiveBuff));

	// Added by Frederick Lachica for NETS GPRS - 4/24/04
	if (lnMessage != 0L)
		vdDisplayMessageFromFile( lnMessage, STATUS_MSG);

	//mytimeval.tv_sec = inReceiveTimeout;
	//mytimeval.tv_usec = 100;
	// Modified by Frederick_L1, don't know the reason for the subtraction of 5 from real value but it seems the timer adds 5 more seconds,
	// need to investigate first
	inReceiveTimeout /= 100;	// Frederick_L1, divide the receive timeout because inReceiveTimeout is for modem timeout (multiply by 100)

	if (inReceiveTimeout < 5)
	{
			mytimeval.tv_sec = inReceiveTimeout;
			mytimeval.tv_usec = 0; //(45 - 5) * 1000;
	}
	else
	{
		mytimeval.tv_sec = (inReceiveTimeout - 5);
		mytimeval.tv_usec = 0; //(45 - 5) * 1000;
	}
	setsockopt(GPRShandle, SOL_SOCKET, SO_RCVTIMEO, (char*) &mytimeval, sizeof(mytimeval) );
	
	retVal = recv(GPRShandle,ReceiveBuff, sizeof(ReceiveBuff), 0);
	if(retVal > 0) {
		inReceiveSize = retVal - 2;
		memcpy(pchReceiveBuff, &ReceiveBuff[2], inReceiveSize);
		return inReceiveSize;
	}
	else	 if (retVal == VS_ERR)// Frederick_L1, If the receiving of data failed, set the transaction error to failed to inform user of what happened
		if (errno == ETIMEDOUT)
			retVal = VS_TIMEOUT;
	
	return retVal;

}

int inEndUCLGPRSCommunication(COMM_OBJECT *obCommunication)
{
	short  retVal = 0;
	
	retVal = closesocket(GPRShandle);

	return VS_SUCCESS;
}

int inFlushUCLGPRSCommunication(void)
{
	return VS_SUCCESS;
}
int inDeInitUCLGPRSCommunication(COMM_OBJECT *obCommunication)
{
	return VS_SUCCESS;
}

int Socket_Connect(unsigned char *port, unsigned char *hostip)
{
   int handle,retVal;
   struct sockaddr_in socket_host;
   short Port = 0;
   
   Port = atoi((char*)port);
   handle = socket(AF_INET,SOCK_STREAM,0);

   socket_host.sin_family = AF_INET;
   memset(socket_host.sin_zero,0,8);
   socket_host.sin_addr.s_addr = htonl(inet_addr((char*)hostip));
   socket_host.sin_port = htons(Port);

   retVal = connect(handle,(struct sockaddr *)&socket_host,sizeof(struct sockaddr_in));

   if(retVal >=0){
   		LOG_PRINTF(("Socket_Connect: Handle >= 0")); //LeeChyi - Addition logging
	   return handle;
	}
	else{
		LOG_PRINTF(("Socket_Connect Error: %d", errno)); //LeeChyi - Addition logging
		closesocket(handle); /* LeeChyi - 07102005 */
		return retVal;
	}

}

int inEditGPRSOperation(TRANSACTION_OBJECT *pobTran)
{
	inConfRecEdit("GPT");
	return(BRANCH_EXIT);
}

int inEditMGTOperation(TRANSACTION_OBJECT *pobTran)
{
	inConfRecEdit("MGT");
	return(BRANCH_EXIT);
}


int inCheckUCLStatus(TRANSACTION_OBJECT *pobTran)
{
	int inRadio=get_env_int("*RADIO");
	inLoadTCPRec(0);
	
	if(inRadio == GPRS_RADIO)
	{
		inCheckGPRSStatus(pobTran);
		return VS_SUCCESS;
	}
	else if((inRadio == ETHERNET_RADIO) && ( inGetIPEnable() == 2 ))
	{
		inCheckWIFIStatus(pobTran);
		return VS_SUCCESS;
	}
	else
	{
	return VS_SUCCESS;
	}
}

int inCheckWIFIStatus(TRANSACTION_OBJECT *pobTran)
{
	int handle_clock=-1;
	static int inStatusCount = 10;
	int inRadio=get_env_int("*RADIO");
	int inReconnect;
	char szReconnect[2];
	unsigned char szUCLRespBuffer[MAX_RESPONSE_LEN];
	char szUCLCmd[20];
	int retVal;
	
	int inPingTime = get_env_int("*PINGTIME");
	int inPingRetVal = -1;
	
	//if(inRadio != ETHERNET_RADIO)
	//	return VS_SUCCESS;
	
	memset(szUCLRespBuffer, 0x00, MAX_RESPONSE_LEN);
	vdWIFIDisplayWireless(inSignalStrength, inWIFINetStatus);
	#if __thumb //start KiaSoon 12122005 - One-Source
	///LOG_PRINTF(("GET SIGNAL VX"));
	inSignalStrength = comnObj->GetStatus(comnObj, ABS_SIGNAL, timer);	
	inWIFINetStatus= comnObj->GetStatus(comnObj, DEVICE_STATUS, timer);
	LOG_PRINTFF((0x8L, "InSignalStrength=%d", inSignalStrength));
	LOG_PRINTFF((0x8L, "inWIFINetStatus=%d", inWIFINetStatus));
	
	#endif
	
	if (CHK_TIMEOUT(handle_clock,ulCheckTimeout))
		return VS_SUCCESS;

	ulCheckTimeout = set_itimeout(handle_clock, 60, TM_SECONDS);
	
	
	#if _TARG_68000 //start KiaSoon 12122005 - One-Source
	//LOG_PRINTF(("GET SIGNAL 3750"));
	strcpy(szUCLCmd, "AT+iRP10");
	
	szUCLCmd[8]='\r';
	retVal = comnObj->SendCommand(comnObj,szUCLCmd,9,szUCLRespBuffer,timer);
	LOG_PRINTFF((0x8L, "UCL: %s", szUCLRespBuffer));
	if(retVal==UCL_SUCCESS)
	{
		int i=0, j=0, k=0;
		char szSignalLevel[4];
		memset(szSignalLevel, 0x00, 4);
		if(szUCLRespBuffer[3]=='4')
		   {
		   	inWIFINetStatus=CONNECTED;
		   }
		else
		{
			inWIFINetStatus=DISCONNECTED;
		}
		for(i=0; szUCLRespBuffer[i]!=0x00; i++)
		{
			if(szUCLRespBuffer[i]==',')
			{
			    j++;
			    
			    if(j==2)
			    	k=i+1;
			 }   
				
			if(j==3)
			    break;	
		}
		//LOG_PRINTFF((0x8L,"i= %d", i));
		//LOG_PRINTFF((0x8L,"j= %d", j));
		//LOG_PRINTFF((0x8L,"k= %d", k));
		memcpy(szSignalLevel, &szUCLRespBuffer[k], (i)-k);
		inSignalStrength=atoi(szSignalLevel);
		LOG_PRINTFF((0x8L,"inSignalStrength= %d", inSignalStrength));
		
	}
	vdWIFIDisplayWireless(inSignalStrength, inWIFINetStatus);
	#endif //end KiaSoon 12122005 - One-Source
	
	
	
	if (inWIFINetStatus != CONNECTED && inWIFINetStatus != OPENED)
	{
		vdSetActionFont();
		clrscr();
		netdisconnect(1);
		vdDisplayAt(1,7,"Reconnecting WIFI...", CLR_EOL);
		vdDisplayAt(1,8,"PLEASE WAIT", CLR_EOL);
		netconnect(1);
		vdSetMenuFont();
		vdSelectMenu(ROOT_MENU_ID);
    		return(BRANCH_EXIT);
	}	
	return (VS_SUCCESS);
}

int inCheckGPRSStatus(TRANSACTION_OBJECT *pobTran)
{
	int handle_clock=-1;
	//char szSignalBuff[MESSAGE_SIZE+1];
	//char szTermIP[MESSAGE_SIZE+1];	// Frederick_L1 071304, added for terminal IP checking
	char szTIP[20]; //Added by Anna Vida Garcia
	char azApn[20+1];
	int inRadio=get_env_int("*RADIO");
	char version[50+1];
	
	/* LeeChyi - 15092005: START*/
	char buffer[20];
	char cmd[10];
	unsigned char respBuffer[MAX_RESPONSE_LEN];
	static int inStartCount=0;
	static int inGPRSCount=0;
	
	int inProfile=get_env_int("*PROFILE");
	int inPingTime = get_env_int("*PINGTIME");
	int inPingRetVal = -1;
	/* LeeChyi - END */
	
	if(inRadio != GPRS_RADIO)
		return VS_SUCCESS;
	
	/* LeeChyi - 15092005: START
		The command needs to be send after some delay. At the start of the program, there are lots
		of initialization and commands to be sent. And this command is not accepted.
		Hence, set a counter so that this command is sent ONCE only at the 10th loop. 
		This command is to put the modem to a SLEEP mode for power saving.
	*/
	
	if (inStartCount < 10){
		inStartCount ++;
	}
	else if (inStartCount == 10){
		memset(cmd, 0, 10);
		strcpy(cmd,"AT+CFUN=8");
		comnObj ->SendCommand(comnObj, (unsigned char *)cmd, strlen(cmd),respBuffer, timer);
		inStartCount ++; 
	}
	else{
		// Keep on setting the counter to be 11 so that the sleep mode command will not be activated again
		inStartCount = 11;	
	}
	/* LeeChyi - END */

	//start albert_d1 -07202005 - Will display battery status if terminal is vx610
	memset(version, 0x00, sizeof(version));
  	SVC_INFO_EPROM(version); //get OS version
	if (strstr(version, "QB") != (char *) NULL){	
		DisplayBatteryStatus();	 
	}
	//end albert_d1 -07202005 - Will display battery status if terminal is vx610
	
	vdGPRSDisplayWireless(inSignalStrength, inGPRSNetStatus, inPDPContextStatus);

	#if 1
	//LeeChyi - 16092005: Modified
	//if(inLoadGPTRec(0) != VS_SUCCESS)
	if(inLoadGPTRec(inProfile-1) != VS_SUCCESS)
		return VS_ERR;

	memset(azApn, 0x00, sizeof(azApn));
	strcpy(azApn, szGetAPN());

	memset(szTIP, 0x00, sizeof(szTIP));
	strcpy(szTIP, szGetTerminalIP());

	if(strlen(azApn) == 0 || strlen(szTIP) == 0)
		return VS_SUCCESS;

	//if (fGetForceReboot() == VS_TRUE)
	//	return VS_SUCCESS;
	#endif
	
	// check the signal every 10 seconds
	if (CHK_TIMEOUT(handle_clock,ulCheckTimeout))
		return VS_SUCCESS;

	ulCheckTimeout = set_itimeout(handle_clock, 10, TM_SECONDS);

	 /* LeeChyi - 07102005: Change the timer from 2 sec to 3 sec */
	/* timer->SetTimer(2000L); */
	timer->SetTimer(3000L);
	
	inGPRSNetStatus= comnObj->GetStatus(comnObj, DEVICE_STATUS, timer);	// Frederick_L1, check the DEVICE_STATUS so you can check GPRS network Status
	LOG_PRINTF(("inGPRSNetStatus = %d", inGPRSNetStatus)); 
		
	vdGPRSDisplayWireless(inSignalStrength, inGPRSNetStatus, inPDPContextStatus);
	
	/* LeeChyi - 15092005: START
		If user selected RETRY - Yes in the intial NETCONNECT FAILED, then in this loop, we shall keep on trying 
		to connect to the GPRS network.
	*/
	
	if (fRetryGPRS){
		if (inGPRSNetStatus != CONNECTED)
		{			
			SocketProgram(1,VS_TRUE);
		}
	}
	
	/* Only if the terminal is connected to the GPRS network, with a minimum signal strength, then we 
		check for PDPContext Status. Since if terminal is not connected to GPRS network, we can assume
		that PDPContext Status will definitely return failure. */
	
	if (inGPRSNetStatus == CONNECTED){
		
		inSignalStrength = comnObj->GetStatus(comnObj, ABS_SIGNAL, timer);	

		LOG_PRINTF(("inSignalStrength = %d", inSignalStrength)); 

		
		/* memset(cmd, 0, 10);
 		memset(respBuffer, 0, MAX_RESPONSE_LEN);
		LOG_PRINTF(("Send Command to Query ATTACH"));
		strcpy(cmd,"AT+CGATT=?");	//1 to activate; 0 to deactivate
		comnObj ->SendCommand(comnObj, (unsigned char *)cmd, strlen(cmd),respBuffer, timer);
		LOG_PRINTF(("Response: %s", respBuffer)); */

		/* LeeChyi - 15092005: START
			The network connection should be ok before we check for PDPContext Status.
			This is to check for the PDPContext Status. Once a negative status is detected, attempt to deactivate
			the current PDPContext and re-activate the PDPContext
		*/
			
		if (inSignalStrength >= MIN_SIGNAL){
			inPDPContextStatus = comnObj->GetStatus(comnObj, PDPCONTEXT_STATUS, timer);	
			LOG_PRINTF(("inPDPContextStatus = %d", inPDPContextStatus)); 
		
			 if (inPDPContextStatus != UCL_SUCCESS){
		 		/* memset(cmd, 0, 10);
		 		memset(respBuffer, 0, MAX_RESPONSE_LEN);
				LOG_PRINTF(("Send Command to deactivate PDPContext"));
				strcpy(cmd,"AT+CGACT=0,1");	//1 to activate; 0 to deactivate
				comnObj ->SendCommand(comnObj, (unsigned char *)cmd, strlen(cmd),respBuffer, timer);
				LOG_PRINTF(("Response: %s", respBuffer));
				
		 		memset(cmd, 0, 10);
		 		memset(respBuffer, 0, MAX_RESPONSE_LEN);
				LOG_PRINTF(("Send Command to activate PDPContext"));
				strcpy(cmd,"AT+CGACT=1,1");	//1 to activate; 0 to deactivate
				comnObj ->SendCommand(comnObj, (unsigned char *)cmd, strlen(cmd),respBuffer, timer);
				LOG_PRINTF(("Response: %s", respBuffer));
				
				inPDPContextStatus = comnObj->GetStatus(comnObj, PDPCONTEXT_STATUS, timer);	
				LOG_PRINTF(("inPDPContextStatus = %d", inPDPContextStatus)); */
				
				SocketProgram(1,VS_TRUE);
				
			}
		}
		else{
			SocketProgram(1,VS_TRUE); //qq
		}
	}
		
	/* LeeChyi - END */		
	
	/* LeeChyi - 21092005: Start
		inPingTime is used to indicate the time interval needed to send a ping message
		if inPingTime = 0, this means that no ping messages are NOT required. */
	
	if (inPingTime == 0){
		return (VS_SUCCESS);
	}
	
	/* This is to set the timer for the first time as well as getting the IP address to be pinged to */
    if (inGPRSCount == 0){
    	ulTimer = set_itimeout(NO_CLOCK_HANDLE (unsigned int)inPingTime, TM_SECONDS);
    	inGPRSCount = 1;
    	
    	memset(szPingIP, 0, 16);
    	get_env("PINGIP", szPingIP, 16);
   	}
	
    if (CHECK_TIMEOUT(ulTimer) == 0){
    	
    	/* If no IP address is being defined, then don't ping */	
    	if (strlen(szPingIP) != 0){
			inPingRetVal = ping(szPingIP);
			LOG_PRINTF(("PING IP Address: %s", szPingIP));
			LOG_PRINTF(("inPingRetVal = %d", inPingRetVal));
			
			if (inPingRetVal <= 0 || inPingRetVal > 60000){
				LOG_PRINTF(("errno = %d", errno));
				
				/* EFAULT: One or more parameters are invalid. */
				/* ENOSOCKAVLBL: no socket can be created for this operation.*/
				/* ENETUNREACH: netconfig must be called successfully before calling ping().*/
				/* EHOSTUNREACH: DNS servers are unreachable or not found. */
				/* EHOSTNORESP: No response from the host to the ping request */
				
				SocketProgram(1,VS_TRUE);
			}
			
			
			
			/* Reset the timer */
			ulTimer = set_itimeout(NO_CLOCK_HANDLE (unsigned int)inPingTime, TM_SECONDS);
		}
	}
	/* LeeChyi - END */
	
	return (VS_SUCCESS);

}

void DisplayBatteryStatus(void)
{
	//LeeChyi - 09092005: Start
	/* Commented off this block since vdDisplayBattery in logo.c has already taken care of
		the battery display, even when the terminal is GPRS enabled */
		
   #if 0
	static int counter=1;
	int charge=0;
		int status;
		static VS_BOOL please=VS_TRUE;
		int inRow=1;
		int inRadio=get_env_int("*RADIO");

		if(inRadio == GPRS_RADIO)
			inRow=2;

		charge=get_battery_charge();
		status=get_battery_status();

		LOG_PRINTF(("Display Battery Status"));
		
		vdSetEntryFont(VS_TRUE);
		if(charge <= 0 || status == -1)//-1 means no battery
		{
			gotoxy(inRow, 6);
	       vdDisplayFontChar(UTILITY_FONT, 34);
	       LOG_PRINTF(("No battery"));
		}
		else if (charge >= 1)
		{
			
			if (get_dock_status() == HANDHELD_UNDOCKED)
			{
				LOG_PRINTF(("Not charging"));
			if ((charge >= 81) && (charge <= 110))
			{
				gotoxy(inRow, 6);
				vdDisplayFontChar(UTILITY_FONT, 39); /*4 bars*/
			}
			else if ((charge >= 61) && (charge <= 80))
			{
				gotoxy(inRow, 6);
				vdDisplayFontChar(UTILITY_FONT, 38); /*3 bars*/
			}
			else if ((charge >= 41) && (charge <= 60))
			{
				gotoxy(inRow, 6);
				vdDisplayFontChar(UTILITY_FONT, 37); /*2 bars*/
			}
			else if ((charge >= 21) && (charge <= 40))
			{
				gotoxy(inRow, 6);
				vdDisplayFontChar(UTILITY_FONT, 36); /*2 bars*/
			}
			else if ((charge >= 1) && (charge <= 20))
			{
				gotoxy(inRow, 6);
				vdDisplayFontChar(UTILITY_FONT, 35); /*1 bar*/
				if(get_dock_status() == -1)//meaning using battery, if 0 using AC
				{
					if(please == VS_TRUE)
					{
						vdDisplayAt(3, 8, "PLEASE CHARGE", CLR_EOL);
						please=VS_FALSE;
					}
					else
					{
						vdDisplayAt(3, 8, "   BATTERY    ", CLR_EOL);
						please=VS_TRUE;
					}
				}
				else
					vdDisplayAt(3, 8, " ", CLR_EOL);
			}
		}
		}
		else{
			LOG_PRINTF(("Charging"));
			//Charging
			//As long as it is not fully charged, display charging bars
			if (charge > 100){
				//fully charged
				gotoxy(inRow, 6);
				vdDisplayFontChar(UTILITY_FONT, 39); /*4 bars*/
				LOG_PRINTF(("Fully charged"));
			}
			else{
				if (counter == 1){
					gotoxy(inRow, 6);
					vdDisplayFontChar(UTILITY_FONT, 35); /*1 bar*/
					counter ++;
					LOG_PRINTF(("1 bar"));
				}
				else if (counter == 2){
					gotoxy(inRow, 6);
					vdDisplayFontChar(UTILITY_FONT, 37); /*2 bars*/
					counter ++;
					LOG_PRINTF(("2 bar"));
				}
				else if (counter == 3 ){
					gotoxy(inRow, 6);
					vdDisplayFontChar(UTILITY_FONT, 38); /*3 bars*/
					counter ++;
					LOG_PRINTF(("3 bar"));
				}
				else if (counter == 4){
					gotoxy(inRow, 6);
					vdDisplayFontChar(UTILITY_FONT, 39); /*4 bars*/
					counter = 1;
					LOG_PRINTF(("4 bar"));
				}
			}
		}
	vdSetIdleFont(VS_TRUE);
	#endif
	//LeeChyi - END
}

void vdGPRSDisplayWireless(int inSignalStatus, int inNetStatus, int inPDPContextStatus)
{
	
	#if __thumb //start albert_d1 07202005 - One-Source
	int line=5;
	#else
	int line=4;
	#endif  //end albert_d1 07202005 - One-Source
	
	vdSetEntryFont(VS_TRUE);
	
	if((inSignalStatus <= 0) || (inNetStatus != CONNECTED))
	{
		 gotoxy(1, 6);
      	 vdDisplayFontChar(UTILITY_FONT, 24);
		 gotoxy(1, 4);
      	 vdDisplayFontChar(UTILITY_FONT, 30);      
      	 	 
      	 /* LeeChyi - 09092005: Added */
		gotoxy(2, 4);
      	vdDisplayFontChar(UTILITY_FONT, 30);      	 
	}
	else if (inSignalStatus >= 1)
	{ 	
		/* LeeChyi - 15092005: START 
			This BLOCK is commented off to make the number of bars more accurate
			with actual signal strength
		*/
		/*
		if ((inSignalStatus >= 25) && (inSignalStatus <= 31))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 29);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
		else if ((inSignalStatus >= 19) && (inSignalStatus <= 24))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 28);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
		else if ((inSignalStatus >= 13) && (inSignalStatus <= 18))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 27);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
		else if ((inSignalStatus >= 7) && (inSignalStatus <= 12))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 22);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
		else if ((inSignalStatus >= 1) && (inSignalStatus <= 6))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 22);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 25);
		}*/
		/* LeeChyi - END */
		
		/* LeeChyi - 15092005: START 
			Maximum strength is 31 and  an acceptable signal strength for transmission
			is about 15. 
			Hence:
			- signal strength of less than 12 - 0 bar
			- signal strength of 12 to 15 - 1 bar
			- signal strength of 16 to 19 - 2 bar
			- signal strength of 20 to 23 - 3 bar
			- signal strength of 24 to 27 - 4 bar
			- signal strength of 28 to 31 - 5 bar
			
		*/
		if ((inSignalStatus >= 28) && (inSignalStatus <= 31))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 29);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
		else if ((inSignalStatus >= 24) && (inSignalStatus <= 27))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 28);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
		else if ((inSignalStatus >= 20) && (inSignalStatus <= 23))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 27);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
		else if ((inSignalStatus >= 16) && (inSignalStatus <= 19))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 22);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
		else if ((inSignalStatus >= 12) && (inSignalStatus <= 15))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 22);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 25);
		}
		else
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 22);
			gotoxy(1, 6);
      	 	vdDisplayFontChar(UTILITY_FONT, 24);
			gotoxy(2, 4);
      		vdDisplayFontChar(UTILITY_FONT, 30);      	
		}
		
		/* Displaying the G status */	
		if (inSignalStatus >= 12 && inSignalStatus <= 31){
			if (inPDPContextStatus == UCL_SUCCESS){
				gotoxy(2, 4);
		   		vdDisplayFontChar(UTILITY_FONT, 41);
			}
			else{
		  		gotoxy(2, 4);
		    	vdDisplayFontChar(UTILITY_FONT, 40);
			}
		}
		/* LeeChyi - END */
	}
	vdSetIdleFont(VS_TRUE);
}

void vdWIFIDisplayWireless(int inSignalStatus, int inNetStatus)
{
#if __thumb //start KiaSoon 12122005 - One-Source
	int line=5;
	LOG_PRINTF(("InDISPLAYWIFI_VX"));
	vdSetEntryFont(VS_TRUE);
	//if((inSignalStatus <= 0) || (inNetStatus != CONNECTED))
	//{
	//	gotoxy(1, 6);
      	// 	vdDisplayFontChar(UTILITY_FONT, 24);
	//	gotoxy(1, 4);
      	 //	vdDisplayFontChar(UTILITY_FONT, 30);      
	//}
	
	if ((inSignalStatus >= 81) && (inSignalStatus <= 100))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 29);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
	else if ((inSignalStatus >= 61) && (inSignalStatus <= 80))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 28);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
	else if ((inSignalStatus >= 41) && (inSignalStatus <= 60))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 27);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
	else if ((inSignalStatus >= 21) && (inSignalStatus <= 40))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 22);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
		}
	else if ((inSignalStatus >= 1) && (inSignalStatus <= 20))
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 22);
			gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 25);
		}
	else
		{
			gotoxy(1,line);vdDisplayFontChar(UTILITY_FONT, 22);
			gotoxy(1, 6);
      	 		vdDisplayFontChar(UTILITY_FONT, 24);
			gotoxy(2, 4);
      			vdDisplayFontChar(UTILITY_FONT, 30);      	
		}
	vdSetIdleFont(VS_TRUE);	
		
#else
	int line=4;
	vdSetEntryFont(VS_TRUE);
	//if((inSignalStatus <= 0) || (inNetStatus != CONNECTED))
	//{
	//	gotoxy(1, 6);
      	// 	vdDisplayFontChar(UTILITY_FONT, 24);
	//		gotoxy(1, 4);
      	// 	vdDisplayFontChar(UTILITY_FONT, 30);      
	
	//}
	if ((inSignalStatus >= 81) && (inSignalStatus <= 100))
	{
		gotoxy(1,4);vdDisplayFontChar(UTILITY_FONT, 29);
		gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
	}
	else if ((inSignalStatus >= 61) && (inSignalStatus <= 80))
	{
		 gotoxy(1,4);vdDisplayFontChar(UTILITY_FONT, 28);
		 gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
	}
	else if ((inSignalStatus >= 41) && (inSignalStatus <= 60))
	{
		 gotoxy(1,4);vdDisplayFontChar(UTILITY_FONT, 27);
		 gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
 	}
	else if ((inSignalStatus >= 21) && (inSignalStatus <= 40))
	{
		 gotoxy(1,4);vdDisplayFontChar(UTILITY_FONT, 22);
		 gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 26);
	}
	else if ((inSignalStatus >= 1) && (inSignalStatus <= 20))
	{
		 gotoxy(1,4);vdDisplayFontChar(UTILITY_FONT, 22);
		 gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 25);
	}
	else
	{
		gotoxy(1,4);vdDisplayFontChar(UTILITY_FONT, 22);
		gotoxy(1,6);vdDisplayFontChar(UTILITY_FONT, 24);	
	}
	
	vdSetIdleFont(VS_TRUE);
	#endif
}


// Frederick_L1 060704, check if terminal need to Reboot due to changes in GPRS config

int inCheckForceReboot(TRANSACTION_OBJECT * pobTran)
{
	char szMessage[MESSAGE_SIZE+1];
	char szTIP[20]; //Added by Anna Vida Garcia
	char azApn[20+1];
	
	int inProfile=get_env_int("*PROFILE"); //LeeChyi - 16092005: Added
	
	//LeeChy - 16092005: Modified
	//if(inLoadGPTRec(0) != VS_SUCCESS)
 	if(inLoadGPTRec(inProfile-1) != VS_SUCCESS)
	 	return VS_ERR;

	memset(azApn, 0x00, sizeof(azApn));
	strcpy(azApn, szGetAPN());

   	memset(szTIP, 0x00, sizeof(szTIP));
	strcpy(szTIP, szGetTerminalIP());

	if(strlen(azApn) == 0 || strlen(szTIP) == 0)
	{
		vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, "SET GPRS PARAMETERS", CLR_EOL);

		SVC_WAIT(2000);

		vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, "             ", CLR_EOL);
		vdSGErrorMessage(0L);	// to suppress the error message
		return VS_ERR;
	}


	if (fGetForceReboot() == VS_FALSE)
		return VS_SUCCESS;

	memset(szMessage, 0x00, MESSAGE_SIZE+1);
	//vdGetMessageFromFile(NETS_PLEASE_REBOOT, szMessage);

	vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, "PLEASE REBOOT", CLR_EOL);
	SVC_WAIT(2000);

	vdDisplayAt(obDisp.inHomeCol, obDisp.inStatusLine, "             ", CLR_EOL);
	vdSGErrorMessage(0L);	// to suppress the error message
	return VS_ERR;
}

// Frederick_L1 060704, resets the ForceReboot during cold boot operation
int inResetForcereboot(TRANSACTION_OBJECT *pobTran)
{
	int inProfile=get_env_int("*PROFILE"); //LeeChyi - 16092005: Added
	
	//LeeChyi - 16092005: Modified
	//if(inLoadGPTRec(0) != VS_SUCCESS)
	if(inLoadGPTRec(inProfile-1) != VS_SUCCESS)
	 	return VS_ERR;

	vdSetForceReboot(VS_FALSE);

	if(inSaveGPTRec(0) != VS_SUCCESS)
	 	return VS_ERR;

	return VS_SUCCESS;
}

#if 0
// Added by Anna Vida Garcia - This function is needed for the printing of error msg as per NETS requirements
// This function was derived from the inNETSPrintFullReceipt function in NETSPrnt.c module.  The comments of the people who made the code were left also.
// Note: There were minor changes made to the function so as to have it work in this particular module.

int inNETSGPRSPrintFullReceipt(TRANSACTION_OBJECT* pobTran)
{
	DB_FILE dbReprintFile;
       int inRetTranCode;
	char szPrintBuffer[24 + 1];
	char szMessageBuffer[MESSAGE_SIZE + 1];
	//START MS111103: Added For CashBack Fee
	char szAmtBuff[AMT_SIZE + 1];
	long lnAccumValue;
	//END MS111103: Added For CashBack Fee
	int inCount = 0;
	unsigned long lnNETSHeaderCondition,lnNETSTopCondition,lnNETSMiddleCondition,lnNETSBottomCondition;

	//START: Praveen 11122003 Error Handling
	if(inLoadHDTRec(0) != VS_SUCCESS)
       {
		vdDisplayMessageFromFile( HDT_ERR_MSG21, WARNING_MSG);
		return VS_ERR;
       }

	if(inLoadMHTRec(0) != VS_SUCCESS)
       {
		vdDisplayMessageFromFile( MHT_ERR_MSG21, WARNING_MSG);
		return VS_ERR;
       }

	if(inLoadMITRec(0) != VS_SUCCESS)
	{
		vdDisplayMessageFromFile( MIT_ERR_MSG21, WARNING_MSG);
		return VS_ERR;
       }
       //END: Praveen 11122003 Error Handling

	if (pobTran->fPreprinted)
		    return(VS_SUCCESS);
	inGetReceiptTemplate(pobTran);
        p350ColumnMode(COLUMN_TYPE_24);
    //Praveen 0707 ATS 328
	if (fGetEnablePrinter())
	{
        vdClearASCII8x21Window(1, 6, 21, 7);            // venu 14082003 to clear nonstatus lines
	 vdDisplayMessageFromFile( PRINTING_MSG, STATUS_MSG);
	}
	//Praveen 0707 ATS 328

    inRetTranCode = inGGCode();

    #ifdef NETS_DOWNLOAD_MULTIPLE_LOGO
     if((inRetTranCode == NETS_PURCHASE) ||  (inRetTranCode == NETS_ADJUST_CASH) ||
	  (inRetTranCode == NETS_ADJUST_REFUND)|| (inRetTranCode == NETS_ADJUST_PURCHASE) ||
	  (inRetTranCode == NETS_REFUND) || (inRetTranCode == NETS_CASHBACK) ||
	  (inRetTranCode == NETS_PURCH_CBACK) || (inRetTranCode == NETS_BALANCE) ||
	  (inRetTranCode == NETS_ADJUST_PURCHASE))
	{
		if (get_env_int("*LOGO") != 0)
		{
			if(inNETSMultipleDownloadLogo(0) == VS_SUCCESS)
			{
				if (inPrintLines(&obPrinter, 137, 137, NO_BL_LINE, 0L) != VS_SUCCESS);
				put_env_int ("*LOGO", 0 );
			}
			else
			{
				 memset(szMessageBuffer,'\0',sizeof(szMessageBuffer));
				 vdGetMessageFromFile(DOWNLOAD_LOGO_FAIL,(char *)szMessageBuffer);
				 vdDisplayMessage((char *)szMessageBuffer,WARNING_MSG);
			}
		}
		else
			if (inPrintLines(&obPrinter, 137, 137, NO_BL_LINE, 0L) != VS_SUCCESS);
    	}
/*	 else if((inRetTranCode == CC_REFUND_CASH) || (inRetTranCode == CC_PURCHASE) ||
	 	      (inRetTranCode == CC_TOPUP_CASH) || (inRetTranCode == CC_TOPUP_NETS) ||
	 	      (inRetTranCode == CC_REFUND_NETS))

	{
		if (get_env_int("*LOGO") != 2)
		{
			if(inNETSMultipleDownloadLogo(2) == VS_SUCCESS)
			{
				if (inPrintLines(&obPrinter, 137, 137, NO_BL_LINE, 0L) != VS_SUCCESS);
				put_env_int ("*LOGO", 2 );
			}
			else
			{
				memset(szMessageBuffer,'\0',sizeof(szMessageBuffer));
				vdGetMessageFromFile(DOWNLOAD_LOGO_FAIL,(char *)szMessageBuffer);
				vdDisplayMessage((char *)szMessageBuffer,WARNING_MSG);
			}
		}
		else
			if (inPrintLines(&obPrinter, 137, 137, NO_BL_LINE, 0L) != VS_SUCCESS);
      }*/
     #endif


	vdNETSGetReceiptHeader(pobTran);
	vdNETSSetReceiptHeaderCondition(pobTran);
	if (inPrintLines(&obPrinter, NETS_HEADER_START, NETS_HEADER_END, NO_BL_LINE, lnNETSHeaderCondition) != VS_SUCCESS);

	vdNETSGetReceiptTop(pobTran);
	vdNETSSetReceiptTopCondition(pobTran);
	if (inPrintLines(&obPrinter, NETS_TOP_START, NETS_TOP_END, NO_BL_LINE, lnNETSTopCondition) != VS_SUCCESS);

	vdNETSGetReceiptMiddle(pobTran);
	vdNETSSetReceiptMiddleCondition(pobTran);
	if (inPrintLines(&obPrinter, 143, 147, NO_BL_LINE, lnNETSMiddleCondition) != VS_SUCCESS);

    if(inPrintLines(&obPrinter, 156,156, NO_BL_LINE, 0L) != VS_SUCCESS);

    if(inPrintLines(&obPrinter, 148,149, NO_BL_LINE, lnNETSMiddleCondition) != VS_SUCCESS);

	vdNETSGetReceiptBottom(pobTran);
	vdNETSSetReceiptBottomCondition(pobTran);
	if(strcmp(srRcpt.szErrorMessage, "DECLINED") == 0)
		memset(srRcpt.szHeaderLine, 0x00, RECEIPT_HEADER_SIZE);

    // Added condition  - Anna Vida Garcia
    if(inGGCode() == NETS_PURCHASE)
    {
	    if(inPrintLines(&obPrinter, 156,156, NO_BL_LINE, 0L) != VS_SUCCESS);
    }
    else if (inGGCode() == NETS_PURCH_CBACK)
    {
	    if(inPrintLines(&obPrinter, 156,156, NO_BL_LINE, 0L) != VS_SUCCESS);
		//ATS #675 06082003 Sindhu After amount gets printed should be cons as app transaction
		if (inPrintLines(&obPrinter, 150, 151, NO_BL_LINE, lnNETSBottomCondition) != VS_SUCCESS);
    }
    // End of modifications - AVG

    //START MS111103: Added For CashBack Fee
    //Commented by AVG
    //if (fError == VS_TRUE)
    //{
 	//ATS??? Praveen 19/11/2003 Print Cashback fee even if it is zero
    	if((inGGCode() == NETS_CASHBACK) || (inGGCode() == NETS_PURCH_CBACK)) /*&& (pobTran->srBRec.lnTipAmount > 0L) )*/
    	{
       		if(inGGCode() == NETS_CASHBACK)
         		if(inPrintLines(&obPrinter, 254,254, NO_BL_LINE, 0L) != VS_SUCCESS);
       		long2str(srRcpt.unFrm.srReceipt.szSubTotAmt, pobTran->srBRec.lnTipAmount);//Fee processed
       		vdFormatAmount(srRcpt.unFrm.srReceipt.szSubTotAmt, VS_TRUE);

       		if (inPrintLines(&obPrinter, 253,253, NO_BL_LINE, 0L) != VS_SUCCESS);
	   		lnAccumValue = pobTran->srBRec.lnTipAmount + pobTran->srBKey.lnTotalOfTransactionAmount;
       		sprintf(szAmtBuff, "%06ld", lnAccumValue);
       		strcpy(srRcpt.unFrm.srReceipt.szTotAmt, szAmtBuff);
       		vdTrimLeadZeroes(srRcpt.unFrm.srReceipt.szTotAmt);
       		vdFormatAmount(srRcpt.unFrm.srReceipt.szTotAmt, VS_TRUE);
    	}
    //}
    //END MS111103: Added For CashBack Fee

    // Added condition  - Anna Vida Garcia
    if((inGGCode() == NETS_PURCHASE) || (inGGCode() == NETS_CASHBACK) ||(inGGCode() == NETS_PURCH_CBACK) || (inGGCode() == NETS_BALANCE) || (inGGCode() == NETS_REFUND))
    	{
	    strncpy(szPrintBuffer, "TOTAL    :              ",24);
	    szPrintBuffer[24] = NULL_CH;
	    strcpy(&szPrintBuffer[24 - strlen(srRcpt.unFrm.srReceipt.szTotAmt)], srRcpt.unFrm.srReceipt.szTotAmt);
	    shSpool(&obPrinter, szPrintBuffer);
	    while (get_port_status(obPrinter.inHandle, szPrintBuffer) != 0);
	    vdDelay(150); //DO NOT REMOVE THIS Fix FOr ATS #675 Sindhu 28082003
	    	if(inPrintLines(&obPrinter, 153,153, NO_BL_LINE, 0L) != VS_SUCCESS);
	 	if(inPrintLines(&obPrinter, 156,156, NO_BL_LINE, 0L) != VS_SUCCESS);
    	}
    //ATS #675 06082003 Sindhu After amount gets printed it should be considered as an  approved  transaction
   if((strcmp(pobTran->srBRec.szRespCode,"00") == 0) && (fError == VS_TRUE))
		inPFRStateStoreAll(NETS_APPROVED_STATE, pobTran, 1, 1);
    //ATS #675 06082003 Sindhu After amount gets printed it should be considered as an  approved  transaction

    if (inPrintLines(&obPrinter, 154, 154, NO_BL_LINE, lnNETSBottomCondition) != VS_SUCCESS);
    if(strcmp(srRcpt.szErrorMessage, "SUPERVISOR PIN ERROR") != 0)
        if(inPrintLines(&obPrinter, 155, 155, NO_BL_LINE, lnNETSBottomCondition) != VS_SUCCESS);
    if (inPrintLines(&obPrinter, 156, 156, NO_BL_LINE, 0L) != VS_SUCCESS);

	if(inCount > 0)
	{
		inCount = 0;
		if(inPrintLines(&obPrinter, 157,157, NO_BL_LINE, 0L) != VS_SUCCESS);
	}
     if (inPrintLines(&obPrinter, 252, 252, BL_LINE, 0L) != VS_SUCCESS);

    if(inPrintLines(&obPrinter, 160,160, NO_BL_LINE, 0L) != VS_SUCCESS); //Fix For ATS bug #196

	if ( db_open(&dbReprintFile, REPRINT_FILE_NAME_NETS, SIZE_BATCH_KEY, (O_TRUNC | O_CREAT | O_RDWR)) < 0 )
    {
        return(VS_ERR);
    }

    if ( inWriteBatchData (&dbReprintFile, &pobTran->srBKey, &pobTran->srBRec, DB_APPEND) != VS_SUCCESS )
    {
        vdSGErrorMessage(BATCH_ERR_MSG);
        return(VS_ERR);
    }

    if ( inCloseBatch(&dbReprintFile) != VS_SUCCESS)
    {
        vdSGErrorMessage(BATCH_ERR_MSG);
    }

    vdSGErrorMessage(0L);
    vdSGRespMsg("");
    return(VS_SUCCESS);
	// End of modifications - Anna Vida Garcia
}
#endif


/* ----------------------------------------------------------------------------
   Name 		: inUCLCOInitialize
   Parameters	: none
   Description	: Initialization of the device using UCL
   Returns	: VS_SUCCESS if successful, otherwise VS_ERR
   ----------------------------------------------------------------------------
   Remarks	: KiaSoon  09-12-2005
   ---------------------------------------------------------------------------- */
int inUCLETHInitialize(void)
{
	short  retVal=0;
	short time=0;
	unsigned long  startTime = 0, complTime=0, waitTime = 0;
	//char temp[24];
	int inIndex;
	short shLinktype;
	int inTotal=inGetHDTTotRecs();
	
	int inRadio=get_env_int("*RADIO");
	fInitComm = VS_SUCCESS;
	
	if (inLoadTCPRec(0) != VS_SUCCESS)
		LOG_PRINTF(("inLoadTCPRec ERROR"));
	
	if( inGetIPEnable() == 0 )
		return  VS_SUCCESS;

	//  Creating object for UclFactory structure
	uclFactory = CreateUclFactory();

	//  Creating object for VerixCommTimer structure
	timer = (CommTimer*)CreateVerixCommTimer();
	if(inGetIPEnable() == 1)
	{
		vdDisplayAt(1, 8, "LAN CONFIG...", CLR_EOL);
		COAppObj = CreateAppObj(4); // for Ethernet
		comnObj = uclFactory->Create(COM3, &retVal, (ApplicationObj *)COAppObj, ETHERNET);
		retVal = AssignUcltoTCP(comnObj,timer,20000L,60000L,30000L,15000L,6000L,6000L);
	}

	if( inGetIPEnable() == 2 )
	{
		
		vdDisplayAt(1, 8, "WIFI CONFIG...", CLR_EOL);
		COAppObj = CreateAppObj(5); // for WiFi
		#if __thumb //start KiaSoon 07122005 - One-Source
			comnObj = uclFactory->Create(COM2, &retVal, (ApplicationObj *)COAppObj,WIFI);
		#else
			comnObj = uclFactory->Create(COM3, &retVal, (ApplicationObj *)COAppObj,WIFI);
		#endif //end albert_d1 07202005 - One-Source
		
		retVal = AssignUcltoTCP(comnObj,timer,5000L,60000L,30000L,15000L,6000L,6000L);
	}

	if (retVal != VS_SUCCESS)
	{
		fInitComm = VS_FAILURE;

		vdDisplayAt(1, 8, "Connect Failed", CLR_EOL);
		vdBeep();
	       vdDelay(3000);
	       return(VS_SUCCESS);
	}
	retVal = inSocketProgram();
	fOpenSocket = VS_FALSE;
//	return(retVal);

       return(VS_SUCCESS);
}

/* ----------------------------------------------------------------------------
   Name 		: inInitUCLCOCommunication
   Parameters	: obCommunication - Communication object
   Description	: Allocates memory to the data pointer in the communication object
   Returns	: VS_SUCCESS if successful, otherwise VS_ERR
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inInitUCLETHCommunication (COMM_OBJECT *obCommunication)
{
	return(VS_SUCCESS);
 }

#if 0
 void vdSendRequest(unsigned char *szTransmitBuffer, unsigned int inSendSize)
{
	unsigned char szTmp[8+1];
	unsigned char szHex[8+1];
	unsigned char temp[24+1];

	memset(szTmp,0,sizeof(szTmp));
	memset(szHex,0,sizeof(szHex));
	memset(temp,0,sizeof(temp));

	sprintf((char *) szTmp, "%04d", inSendSize);
	SVC_DSP_2_HEX((char *) szTmp ,(char *) szHex , 2);
	memcpy(temp, szHex, 2);
	memcpy(&temp[2], szTransmitBuffer, inSendSize);
	send(hEthernet, (char *) temp, inSendSize+2, 0);
}

 int inReceiveResponse(unsigned char *szReceiveBuffer, unsigned int inSendSize)
{
	//unsigned char szReceiveBuffer[20+1];
	short retVal;
	int inLen;
	int inSize=0;
	short retry=5;
	struct timeval timeout;
	char temp[5+1];
		/*response*/

	timeout.tv_sec = 300/100;
	timeout.tv_usec = 100;
	setsockopt(hEthernet, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout));

	timeout.tv_sec = 0;
	timeout.tv_usec = 100;
	setsockopt(hEthernet, SOL_SOCKET, SO_PKTRCVTIMEO, (char*)&timeout, sizeof(timeout));

	memset(szReceiveBuffer, 0, sizeof(szReceiveBuffer));
	retVal = 0;

	retVal = recv(hEthernet, (char *) szReceiveBuffer, sizeof(szReceiveBuffer), 0);

}

 int inPreconnectionRequest(void)//to check if preconnection is succesful
{
	char temp_send[10+1];
	char temp_receive[10+1];
	short retTry=3;
	int len;

	if(get_env_int("*GW3750") != 1)
		return VS_TRUE;

	while(retTry!=0)
	{
		memset(temp_send,0,sizeof(temp_send));
		memset(temp_receive,0,sizeof(temp_receive));
		temp_send[0]=0x41;//A for pre-connection
		vdSendRequest((unsigned char *)temp_send, 1);

		len=0;
		len=inReceiveResponse((unsigned char *)temp_receive, 0);
		if(len > 0 && temp_receive[2] == 0x41 && temp_receive[3] == 0x01)
			return VS_TRUE;
		retTry--;
	}
	return VS_FALSE;
}

int inDisconnectionRequest(void)//to check if disconnection is succesful
{
	char temp_send[10+1];
	char temp_receive[10+1];
	short retTry=5;
	int len;

	if(get_env_int("*GW3750") != 1)
		return VS_TRUE;

	while(retTry!=0)
	{
		memset(temp_send,0,sizeof(temp_send));
		memset(temp_receive,0,sizeof(temp_receive));

		temp_send[0]=0x42;//B for pre-connection
		vdSendRequest((unsigned char *)temp_send, 1);

		len=0;
		len=inReceiveResponse((unsigned char *)temp_receive, 0);
		if(len > 0 && temp_receive[2] == 0x42 && temp_receive[3] == 0x01)
			return VS_TRUE;
		retTry--;
	}
	return VS_TRUE;
}

 int inCheckConnection(TRANSACTION_OBJECT *pobTran, short retTry)//to check if connected or not connected
{
	char temp_send[10+1];
	char temp_receive[10+1];
	int len;
	VS_BOOL fError;

	if(get_env_int("*GW3750") != 1)
		return VS_TRUE;

 	if(pre_connection == VS_FALSE)
		inPreconnectionRequest();

	while(retTry!=0)
	{
		memset(temp_send,0,sizeof(temp_send));
		memset(temp_receive,0,sizeof(temp_receive));

		temp_send[0]=0x44;//10 for pre-connection
		vdSendRequest((unsigned char *)temp_send, 1);

		len=0;
		len=inReceiveResponse((unsigned char *)temp_receive, 0);
 		if(len > 0)
		{
			if(temp_receive[2] == 0x44 && temp_receive[3] == 0x01)//connected
				return VS_TRUE;
			else if(temp_receive[2] == 0x44 && temp_receive[3] == 0x03)//no dial tone
			{
				lnDialErrorNo = NETS_GATEWAY_NOLINE_MSG;
	            fError = VS_FALSE;
	            inStoreTranFlexiData(pobTran, NETS_CC_ERROR_FLAG, (unsigned char * )&fError, sizeof(VS_BOOL));
				vdGetMessageFromFile(NETS_GATEWAY_NOLINE_MSG, srRcpt.szErrorMessage);
				vdSGErrorMessage(NETS_GATEWAY_NOLINE_MSG);
				vdDisplayMessage(srRcpt.szErrorMessage, WARNING_MSG);
				inNETSPrintFullReceipt(pobTran);
				lnDialErrorNo=0;
				return VS_FALSE;
			}
		}
		retTry--;
	}
	vdGetMessageFromFile(NETS_GPRSCONNECTFAILED_MSG, srRcpt.szErrorMessage);
	vdSGErrorMessage(NETS_GPRSCONNECTFAILED_MSG);
	vdDisplayMessage(srRcpt.szErrorMessage, WARNING_MSG);
	inNETSPrintFullReceipt(pobTran);
	pre_connection=VS_FALSE;
	return VS_FALSE;
}

/* ----------------------------------------------------------------------------
   Name 		: inPreConnection
   Parameters	: none
   Description	: none
   Returns	: VS_SUCCESS
   ----------------------------------------------------------------------------
   Remarks	: Albert 11-24-2004
   ---------------------------------------------------------------------------- */
int inPreConnection(void)
{
	char szHostIPAddress[25+1];
	int inRetryCount;
	int retVal;
	TRANSACTION_OBJECT *pobTran;
	short waitTime;
	char temp[5+1];

	pobTran = pstGet_pobTran ();
	inLoadHDTRec(inGetHostHandle());
	if(fOpenSocket == VS_TRUE)
		return(VS_SUCCESS);

	//fOpenSocket = VS_FALSE;  // socket is close
	fEndTCP = VS_FALSE;

	if(fInitComm == VS_FAILURE)
	{
		vdDisplayAt(1, 8, "Must Do Restart", CLR_EOL);
		vdBeep();
	       vdDelay(2000);
		return(VS_ERR);
	}

	if(inLoadTCPRec(0) != VS_SUCCESS)
    	{
    		vdDisplayMessageFromFile(IPT_ERR_MSG21, WARNING_MSG);
    		return VS_ERR;
    	}

	vdDisplayAt(1, 8, "PROCESSING...", CLR_LINE);
	memset(szHostIPAddress, 0, sizeof(szHostIPAddress));
	strcpy(szHostIPAddress, szGetHostPrimaryIP());
	//SET timeout value to 6 seconds only,make preconnection timeout shorter
	waitTime = 6;
	setparam(TCP_TIMEOUT,(char*)&waitTime , sizeof(waitTime));

	if(inSocketConnect(szHostIPAddress) == VS_SUCCESS)
	{
   		pre_connection = VS_TRUE;
		fOpenSocket = VS_TRUE;
 		//albert_d1 pre_connection
		if(inPreconnectionRequest() == VS_TRUE)
			pre_connection=VS_TRUE;
		else
			pre_connection=VS_FALSE;

	}
	//return timeout value to its original
	waitTime = inGetIPTCPTO();
	setparam(TCP_TIMEOUT,(char*)&waitTime , sizeof(waitTime));

	//inGetUCLSignalStatus();
	//get_char();

	return(VS_SUCCESS);
}
#endif

/* ----------------------------------------------------------------------------
   Name 		: inBeginUCLCOCommunication
   Parameters	: none
   Description	: none
   Returns	: VS_SUCCESS
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inBeginUCLETHCommunication(COMM_OBJECT *obCommunication, int inCPTIndex, VS_BOOL fUsePrimaryLine)
{
	char szHostIPAddress[25+1];
	int inRetryCount;
	int retVal;
	TRANSACTION_OBJECT *pobTran;


	if(pre_connection == VS_TRUE)
		return(VS_SUCCESS);

	pobTran = pstGet_pobTran ();
	inLoadHDTRec(inGetHostHandle());
	if(fOpenSocket == VS_TRUE)
		return(VS_SUCCESS);

	//fOpenSocket = VS_FALSE;  // socket is close
	fEndTCP = VS_FALSE;

	if(fInitComm == VS_FAILURE)
	{
		vdDisplayAt(1, 8, "Must Do Restart", CLR_EOL);
		vdBeep();
	       vdDelay(2000);
		return(VS_ERR);
	}

	if(inLoadTCPRec(0) !=VS_SUCCESS)
  //  if(inLoadIPTRec(0) != VS_SUCCESS)
    {
    	//vdDisplayMessageFromFile(IPT_ERR_MSG21, WARNING_MSG);
    	return VS_ERR;
    }

	inRetryCount = shGetIPTries();
	inRetryCount = inRetryCount; //inRetryCount = inRetryCount * 2;

	while(inRetryCount)
	{
		if(inRetryCount==shGetIPTries())
			vdDisplayAt(1, 8, "CONNECTING...", CLR_LINE);
		else
			vdDisplayAt(1, 8, "RECONNECTING...", CLR_LINE);

		memset(szHostIPAddress, 0, sizeof(szHostIPAddress));
		if (inRetryCount %2)
		{
			strcpy(szHostIPAddress, szGetHostSecondaryIP());
		}
		else
		{
			strcpy (szHostIPAddress , szGetHostPrimaryIP());
		}

		inRetryCount--;

		retVal = inSocketConnect(szHostIPAddress);
		if (retVal >= 0)
		{
			fOpenSocket = VS_TRUE;
			return(VS_SUCCESS);
		}

		if(inRetryCount)
		{
			vdDisplayAt(1, 8, "PLEASE WAIT...", CLR_LINE);
			SVC_WAIT(5000);
		}
	}
	return(VS_ERR);
}

/* ----------------------------------------------------------------------------
   Name 		: inCheckUCLCOCommunication
   Parameters	: none
   Description	: none
   Returns	: VS_SUCCESS
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inCheckUCLETHCommunication(COMM_OBJECT *obCommunication)
{
	return(VS_SUCCESS);
}

/* ----------------------------------------------------------------------------
   Name 		: inSendUCLCOCommunication
   Parameters	: obCommunication - Communication object
   Description	: Sends the message to the host
   Returns	: Length of message sent if successful, otherwise error code
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inSendUCLETHCommunication(COMM_OBJECT *obCommunication, char *pchSendBuff, int inSendSize,
								VS_BOOL fConfirmSend, int inTimeout, long lnMessage)
{
	unsigned char szTransmitBuffer[600+1];
	unsigned char szTmp[25];
	unsigned char szHex[25];
	int retVal;

	vdDisplayAt(1, 8, "TRANSMITTING...",CLR_LINE);
	memset(szTransmitBuffer, 0x00, sizeof(szTransmitBuffer));
	memset(szTmp, 0x00, sizeof(szTmp));

	if (fGetHexHeader())	// if true then HEX format header else BCD format header
		sprintf((char *) szTmp, "%04X", inSendSize);// remove the +2 for NCC compatibility
	else
		sprintf((char *) szTmp, "%04d", inSendSize);

//	sprintf((char *) szTmp, "%04d", inSendSize);// remove the +2 for NCC compatibility
	SVC_DSP_2_HEX((char *) szTmp ,(char *) szHex , 2);
	memcpy(szTransmitBuffer, szHex, 2);
	memcpy(&szTransmitBuffer[2], pchSendBuff, inSendSize);

#if 0
	if (fGetHexHeader())	// if true then HEX format header else BCD format header
		sprintf(szTmp, "%04X", inSendSize);	// changes due to hypercom NAC, July 1, 2004
	else
		sprintf(szTmp, "%04d", inSendSize);
#endif

	retVal = send(hEthernet, (char *) szTransmitBuffer, inSendSize+2, 0);

	if(retVal<0)
	{
		return VS_TIMEOUT;		//albert_d1
      	//return VS_ERR;
	}

	return(retVal-2);
}

/* ----------------------------------------------------------------------------
   Name 		: inReceiveUCLCOCommunication
   Parameters	: obCommunication - Communication object
   Description	: Waits for reponse from the host
   Returns	: Length of response if successful, otherwise error code
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */

int inReceiveUCLETHCommunication(COMM_OBJECT *obCommunication, char *pchReceiveBuff, int inReceiveSize,
								 int inReceiveTimeout, long lnMessage)
{
	unsigned char szReceiveBuffer[600+1];
	short retVal;
	int inLen;
	int inSize=0;
	struct timeval timeout;
	//char temp[24+1];

	vdDisplayAt(1, 8, "RECEIVING...",CLR_LINE);

	timeout.tv_sec = inReceiveTimeout/100;
	timeout.tv_usec = 100;
	setsockopt(hEthernet, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout));

	timeout.tv_sec = 0;
	timeout.tv_usec = 100;
	setsockopt(hEthernet, SOL_SOCKET, SO_PKTRCVTIMEO, (char*)&timeout, sizeof(timeout));

	memset(szReceiveBuffer, 0, sizeof(szReceiveBuffer));
	retVal = 0;

	retVal = recv(hEthernet, (char *) szReceiveBuffer, sizeof(szReceiveBuffer), 0);

	if (retVal <= 0) // it means a timout occured
    {
		return VS_TIMEOUT;		//albert_d1
      	//return VS_ERR;
    }

	inLen=retVal-2;
	memcpy(pchReceiveBuff, &szReceiveBuffer[2], inLen); // + 2 is added for 2 bytes of length  in packet

	return(inLen);
}

/* ----------------------------------------------------------------------------
   Name 		: inReceiveUCLCOCommunication
   Parameters	: obCommunication - Communication object
   Description	: End the communication between the terminal and the host
   Returns	: VS_SUCCESS if successful, otherwise error code
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inEndUCLETHCommunication(COMM_OBJECT *obCommunication)
{
	int retVal = VS_ERR;
	//char temp[5+1];

	if(fEndTCP==VS_TRUE)
		return VS_SUCCESS;

	//inDisconnectionRequest();
if(fTCUploadCloseModem == VS_FALSE)
	{
		return VS_SUCCESS;
	}
	
	if(fEndTCP==VS_TRUE)
		return VS_SUCCESS;

	obCommunication->inLinkType = NO_COMM;   // reset link type

	retVal = closesocket(hEthernet);

	fOpenSocket = VS_FALSE;

	if (retVal == 0)
		retVal = VS_SUCCESS;

	#if 0

	if (fOpenSocket == VS_TRUE)   // socket is close
	{
		retVal = closesocket(hEthernet);
		fOpenSocket = VS_FALSE;
		if (retVal == 0)
			retVal = VS_SUCCESS;
	}
	else
	{
		inUCLTerminate();
		yield();
		netdisconnect(1);
		inUCLTT0();
		inUCLETHInitialize();
	}
	#endif

	return(retVal);
}

/* ----------------------------------------------------------------------------
   Name 		: inFlushUCLCOCommunication
   Parameters	: none
   Description	: none
   Returns	: VS_SUCCESS
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inFlushUCLETHCommunication(void)
{
	return(VS_SUCCESS);
}

/* ----------------------------------------------------------------------------
   Name 		: inDeInitUCLCOCommunication
   Parameters	: obCommunication - Communication object
   Description	: Deinitializes the communication device
   Returns	: VS_SUCCESS if successful, otherwise error code
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inDeInitUCLETHCommunication(COMM_OBJECT *obCommunication)
{
	int retVal = VS_ERR;

	if(fEndTCP==VS_TRUE)
		return VS_SUCCESS;

	fEndTCP=VS_TRUE;

	obCommunication->inLinkType = NO_COMM;   // reset link type

	retVal = closesocket(hEthernet);

	fOpenSocket = VS_FALSE;

	if (retVal == 0)
		retVal = VS_SUCCESS;

	#if 0

	if (fOpenSocket == VS_TRUE)   // socket is close
	{
		retVal = closesocket(hEthernet);
		fOpenSocket = VS_FALSE;
		if (retVal == 0)
			retVal = VS_SUCCESS;
	}
	else
	{
		inUCLTerminate();
		yield();
		netdisconnect(1);
		inUCLTT0();
		inUCLETHInitialize();
	}
	#endif

	return(retVal);
}

/* ----------------------------------------------------------------------------
   Name 		: inSocketProgram
   Parameters	: none
   Description	: Opens the network device
   Returns	: VS_SUCCESS if successful, otherwise eroor code
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inSocketProgram(void)
{
	short  retVal,waitTime;
	netparams net_param;
	int inTCPTO, inIPType;
	//aldo
	short shWiFiChannel;
	short shWiFiWEPMode;
	short shWiFiWEPIndex;
	short waitTimer;
	struct wepKeyVal key;
	//aldo


	retVal = VS_ERR;

	if (inLoadTCPRec(0) != VS_SUCCESS)
	{
		return retVal;
	}

	if( inGetIPEnable() == 1 )
	{
		vdDisplayAt(1, 8, "IP Config", CLR_EOL);
		memset(&net_param,0,sizeof(net_param));

		inIPType = inGetIPType();
		if (inIPType == 1) // for DHCP
		{
			strcpy(net_param.ipAddress ,"0.0.0.0");
			strcpy(net_param.ipSubnetMask ,"0.0.0.0");
			setparam(GATEWAY,"0.0.0.0",strlen("0.0.0.0"));
			setparam(DNSPRI,"0.0.0.0",strlen("0.0.0.0"));
			setparam(DNSSEC,"0.0.0.0",strlen("0.0.0.0"));
		}
		else // for static
		{
			setparam(MYIP, szGetMyIP(), strlen(szGetMyIP()));
			setparam(SUBNET, szGetSubNetMask(), strlen(szGetSubNetMask()));
			setparam(GATEWAY, szGetGateWay(), strlen(szGetGateWay()));
			setparam(DNSPRI, szGetHostDNS1(), strlen(szGetHostDNS1()));
			setparam(DNSSEC, szGetHostDNS2(), strlen(szGetHostDNS2()));
		}

		net_param.datalinkProtocol = DL_PPP_CO_ETH;
		retVal = SetTimeout(SEND_TIMEOUT,1000L);
		retVal = SetTimeout(RECEIVE_TIMEOUT,3000L);
		retVal = netconfig(&net_param);

		inTCPTO = inGetIPTCPTO();
		waitTime = inTCPTO;
		setparam(TCP_TIMEOUT,(char*)&waitTime , sizeof(waitTime));
		retVal = netconnect(1);
	}

	if( inGetIPEnable() == 2)
	{
		//vdDisplayAt(1, 8, "WIFI CONFIG", CLR_EOL);
		memset(&net_param,0,sizeof(net_param));

		inIPType = inGetIPType();
		if (inIPType == 1) // for DHCP
		{
			strcpy(net_param.ipAddress ,"0.0.0.0");
			strcpy(net_param.ipSubnetMask ,"0.0.0.0");
			setparam(GATEWAY,"0.0.0.0",strlen("0.0.0.0"));
			setparam(DNSPRI,"0.0.0.0",strlen("0.0.0.0"));
			setparam(DNSSEC,"0.0.0.0",strlen("0.0.0.0"));
		}
		else // for static
		{
			setparam(MYIP, szGetMyIP(), strlen(szGetMyIP()));
			setparam(SUBNET, szGetSubNetMask(), strlen(szGetSubNetMask()));
			setparam(GATEWAY, szGetGateWay(), strlen(szGetGateWay()));
			setparam(DNSPRI, szGetHostDNS1(), strlen(szGetHostDNS1()));
			setparam(DNSSEC, szGetHostDNS2(), strlen(szGetHostDNS2()));
		}

		net_param.datalinkProtocol = DL_PPP_CO_WIFI;
		retVal = SetTimeout(SEND_TIMEOUT,2000L);
		retVal = SetTimeout(RECEIVE_TIMEOUT,3000L);
		retVal = netconfig(&net_param);

		shWiFiChannel = shGetWiFiChannel();
		shWiFiWEPMode = shGetWiFiWEPMode();
		shWiFiWEPIndex = shGetWiFiWEPIndex();
		waitTimer = inGetWiFiICReset();

		setparam((int)WIFI_CHANNEL, (char *)&shWiFiChannel, sizeof(short));
		setparam((int)WIFI_SYSID, szGetWiFiSysID(), (int)strlen(szGetWiFiSysID()));

		if (shWiFiWEPMode != 0)
		{
			//if WEP key are enabled.
			setparam((int)WEP_MODE, (char *)&shWiFiWEPMode, sizeof(short));
			setparam((int)WEP_KEYINDEX, (char *)&shWiFiWEPIndex, sizeof(short));
			setparam(WAIT_ICHIPRESET,(char*)&waitTimer , sizeof(waitTimer));

			switch(shWiFiWEPIndex)
			{
				case 1:
					key.index = 1;
					strcpy(key.value,szGetWiFiWEPKeyVal1());
					setparam((int)WEP_KEYVALUE, (char *)&key, (short)sizeof(key));
					break;
				case 2:
					key.index = 2;
					strcpy(key.value,szGetWiFiWEPKeyVal2());
					setparam((int)WEP_KEYVALUE, (char *)&key, (short)sizeof(key));
					break;
				case 3:
					key.index = 3;
					strcpy(key.value,szGetWiFiWEPKeyVal3());
					setparam((int)WEP_KEYVALUE, (char *)&key, (short)sizeof(key));
					break;
				case 4:
					key.index = 4;
					strcpy(key.value,szGetWiFiWEPKeyVal4());
					setparam((int)WEP_KEYVALUE, (char *)&key, (short)sizeof(key));
					break;
				default:
					key.index = 1;
					strcpy(key.value,szGetWiFiWEPKeyVal1());
					setparam((int)WEP_KEYVALUE, (char *)&key, (short)sizeof(key));
					break;
			}
		}

		inTCPTO = inGetIPTCPTO();
		waitTime = inTCPTO;
		setparam(TCP_TIMEOUT,(char*)&waitTime , sizeof(waitTime));
		retVal = netconnect(1);
		#if _TARG_68000 //start KiaSoon 12122005 - One-Source
		if (retVal >= 0)
		{
			unsigned char szUCLRespBuffer[MAX_RESPONSE_LEN];
			char szUCLCmd[20];
			strcpy(szUCLCmd, "AT+iRP10");
	
			szUCLCmd[8]='\r';
			retVal = comnObj->SendCommand(comnObj,szUCLCmd,9,szUCLRespBuffer,timer);
			LOG_PRINTFF((0x8L, "UCL: %s", szUCLRespBuffer));
			if(retVal==UCL_SUCCESS)
			{
				int i=0, j=0, k=0;
				char szSignalLevel[4];
				memset(szSignalLevel, 0x00, 4);
				if(szUCLRespBuffer[3]=='4')
		   		{
		   			inWIFINetStatus=CONNECTED;
		   		}
				else
				{
					inWIFINetStatus=DISCONNECTED;
				}
				for(i=0; szUCLRespBuffer[i]!=0x00; i++)
				{
					if(szUCLRespBuffer[i]==',')
					{
			    			j++;
			   			if(j==2)
			    			k=i+1;
			 		}   
				
					if(j==3)
			    			break;	
				}
				memcpy(szSignalLevel, &szUCLRespBuffer[k], (i)-k);
				inSignalStrength=atoi(szSignalLevel);
			}
		}
		#endif
		
	}

	return(retVal);
}

/* ----------------------------------------------------------------------------
   Name 		: inSocketConnect
   Parameters	: szHostIP - Host IP address
   Description	: Opens the socket and connects to the host
   Returns	: VS_SUCCESS if successful, otherwise VS_ERR
   ----------------------------------------------------------------------------
   Remarks	: Rannie 03-04-2004
   ---------------------------------------------------------------------------- */
int inSocketConnect(char *szHostIP)
{
	int retVal;
	struct sockaddr_in socket_host;


	inLoadTCPRec(0);
	if (inGetIPEnable() == 0)
	{
		  return( VS_SUCCESS);
	}

	if (shGetCommLinkType() != CONNECT_ONE)
	{
		return (VS_SUCCESS);
	}

	retVal = netconnect(1);

	memset(&socket_host, 0, sizeof(socket_host));
	socket_host.sin_family = AF_INET;
	memset(socket_host.sin_zero, 0, 8);
	socket_host.sin_addr.s_addr = htonl(inet_addr(szHostIP));
	socket_host.sin_port = htons(shGetIPPort());

	hEthernet = socket(AF_INET, SOCK_STREAM, 0);

	retVal = connect(hEthernet, (struct sockaddr *)&socket_host, sizeof(struct sockaddr_in));

	if (retVal < 0)
	{
		return VS_ERR;
	}
	return(retVal);
}

int inUCLTerminate(void)
{
	unsigned char respBuffer[MAX_RESPONSE_LEN];
	char cmd[10];

       memset(cmd,0x00,10);

	// vdDisplayAt(1,2,"Send iDOWN",CLR_EOL);
	//LOG_PRINTFF((0x8L,"Send iDOWN"));
	strcpy(cmd,"AT+iDOWN");
	comnObj ->SendCommand(comnObj, (unsigned char *)cmd, strlen(cmd),respBuffer, timer);
	vdDelay(4000);
	//LOG_PRINTFF((0x8L,"RES1 :- %s", respBuffer));
	//vdDisplayAt(1,3,respBuffer,CLR_EOL);
	//get_char();
	return(VS_SUCCESS);
}

int inUCLTT0(void)
{
	unsigned char respBuffer[MAX_RESPONSE_LEN];
	char cmd[20];

       memset(cmd,0x00,20);

	 // vdDisplayAt(1,2,"Send iDOWN",CLR_EOL);
	  //LOG_PRINTFF((0x8L,"Send iDOWN"));
	sprintf(cmd,"AT+iTT0=%d", inGetIPTCPTO());
	comnObj ->SendCommand(comnObj, (unsigned char *)cmd, strlen(cmd),respBuffer, timer);
	vdDelay(4000);
	//LOG_PRINTFF((0x8L,"RES1 :- %s", respBuffer));
	//vdDisplayAt(1,3,respBuffer,CLR_EOL);
	//get_char();
	return(VS_SUCCESS);
}


